#ifndef CMEIVALIDATORIMPL_H_
#define CMEIVALIDATORIMPL_H_

#include <QObject>
#include <mutex>
#include <thread>

#include "IValidatorInterface.h"

class CMEIValidatorImpl : public QObject, public zl::IValidatorInterface
{
public:
    CMEIValidatorImpl();
    ~CMEIValidatorImpl();

    int32_t Initialize(const std::string& com, int32_t baud, zl::IValidatorObserver* obs) override;
    int32_t Uninitialize() override;
    int32_t Status() override;
    int32_t Reset() override;
    int32_t Setup() override;
    int32_t Enable() override;
    int32_t Disable() override;

protected:
    int32_t mdb_cmd_reset();
    int32_t mdb_cmd_setup();
    int32_t mdb_cmd_poll();
    int32_t mdb_cmd_enable();
    int32_t mdb_cmd_disable();
    int32_t write_mdb_buffer(const unsigned char* buf, size_t size);
    int32_t write_mdb_ack();
    int32_t read_mdb_buffer(unsigned char* buf, size_t max_size);

    void timerEvent(QTimerEvent *event);

private:
    struct MEIImpl;
    MEIImpl* impl_;
    std::mutex mutex_;
    zl::IValidatorObserver* obs_;
    int32_t timer_poll_;
    bool flag_init_;

    int32_t status_;
};

#endif // CMEIVALIDATORIMPL_H_
